package com.chb.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.app.service.HealthNewsService;
import com.chb.app.vo.NewsParams;
import com.hos.entity.hos.HealthNews;
import com.hos.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：WuBai-T
 * @date ：Created in 2023/12/22 11:54
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/app/news")
public class HealthNewsController {

    @Autowired
    private HealthNewsService healthNewsService;

    @GetMapping("/getLittleNews")
    public Result<List<HealthNews>> getLittleNews() {
        List<HealthNews> littleNews = healthNewsService.getLittleNews();
        return new Result<List<HealthNews>>(200, "查询成功", littleNews);
    }

    @GetMapping("/getAllNews")
    public Result<List<HealthNews>> getAllNews() {
        List<HealthNews> littleNews = healthNewsService.getAllNews();
        return new Result<List<HealthNews>>(200, "查询成功", littleNews);
    }

    @GetMapping("/getNewsByNewsId/{newsId}")
    public Result<HealthNews> getNewsByNewsId(@PathVariable String newsId) {
        HealthNews newsByNewsId = healthNewsService.getNewsByNewsId(newsId);
        return new Result<HealthNews>(200, "查询成功", newsByNewsId);
    }


    @PostMapping("getNewsByParams")
    @ApiOperation("根据参数查询新闻信息————分页+条件查询")
    public Result<IPage<HealthNews>> getNewsByParams(@RequestBody NewsParams params) {
        return new Result<>(200, "查询成功", healthNewsService.getNewsByParams(params));
    }

    @PostMapping
    @ApiOperation("进行添加新闻信息")
    public Result<Void> insertNews(@RequestBody HealthNews healthNews) {
        this.healthNewsService.insertNews(healthNews);
        return new Result<>(200, "添加成功", null);
    }

    @PutMapping
    @ApiOperation("进行修改新闻信息")
    public Result<Void> updateNews(@RequestBody HealthNews healthNews) {
        this.healthNewsService.updateNews(healthNews);
        return new Result<>(200, "添加成功", null);
    }

    @DeleteMapping("/{newsId}")
    @ApiOperation("进行删除新闻信息")
    public Result<Void> delNews(@PathVariable String newsId) {
        this.healthNewsService.delNews(newsId);
        return new Result<>(200, "删除成功", null);
    }
}